Conversation
Holds scripts to calculate weekly averages and compare to the latest stock price as well as being able to communicate with IFTTT.
This script contains functions that fetches data from the APIs, calculates differences, and communicates with my IFTTT
| communicates with IFTTT by posting a request to trigger | ||
| an email to the assigned Gmail accounts with the IFTTT | ||
| """ | ||
| api_key = "nmSjoGFt5z5ExJ4bLUMBcr0JozQykoHC2TB5dUNdUT4" # my api key for authentication |
There was a problem hiding this comment.
Security: Your API keys are hardcoded in your code. .env + .gitignore would help to avoid committing your key to the public repo.
There was a problem hiding this comment.
That's a really good point, thank you
| json_file = "real_time_stock_data" # name of json file | ||
| recent_stock_prices = [] | ||
|
|
||
| try: |
There was a problem hiding this comment.
Error Handling future suggestions: if an API call fails, you might want to retry it a few times before giving up.
| The reason 5 is because the stock market is only open | ||
| on weekdays. | ||
| """ | ||
| first_five_items = {k: dict[k] for k in list(dict)[:5]} |
There was a problem hiding this comment.
are we sure there will always be at least 5 items in the dictionary? What if there are less than 5, will it raise an error?
|
|
||
| def convert_usd_to_gbp(price_to_convert): | ||
| # a simple function to convert USD to GBP | ||
| return price_to_convert/1.23 |
There was a problem hiding this comment.
You've hardcoded the conversion rate from USD to GBP =1.23. This can be problematic if the conversion rate changes. Consider fetching the conversion rate dynamically
| print("Yes there has been a drop of prices") | ||
| else: | ||
| data = { | ||
| 'Value1':'No updates on the stocks', |
There was a problem hiding this comment.
email triggering: If there's no significant decrease, an email is still sent with the message "No updates on the stocks" - I would avoid spamming.
| total = 0 | ||
| for key, value in given_dict.items(): | ||
| total += return_open_val(value) | ||
| return total/5 |
There was a problem hiding this comment.
The function finalize_dict always grabs the first 5 entries from the returned data. I wonder if this may make your average in calc_weekly_average inaccurate because you're always dividing by 5 (If the market was closed for a holiday within the last 5 weekdays)?
deleted api
deleted api key
No description provided.